﻿using Eamon.MeituanDotnetSDK.utils;
using System;
using System.ComponentModel;
namespace Eamon.MeituanDotnetSDK.api.common.response
{
    [Serializable]
    public class BaseResponse
    {
        public string Code { get; set; }
        public string Msg { get; set; }
        public string TraceId { get; set; }
        public BaseResponse()
        {
        }
        public override string ToString()
        {
            return JsonUtil.ToJson(this);
        }
    }

    [Serializable]
    public class BaseOAuthResponse<T>
    {
        public int Code { get; set; }
        public string Msg { get; set; } // {"code":14,"message":"不支持的业务类型","msg":"不支持的业务类型","traceId":"1510664168240025040"}
        public T Data { get; set; } // {"code":0,"data":{"accessToken":"V2-accessToken","expireIn":2592000,"opBizCode":"opBizCode","opBizName":"opBizName中文","refreshToken":"refreshToken","scope":"tuangou,ugc,merchantdata"},"traceId":"-5101713918391243123"}

        public PlatformResponseCode ToPlatformResponseCode()
        {
            if (Enum.IsDefined(typeof(PlatformResponseCode), Code))
            {
                return (PlatformResponseCode)Code;
            }
            return PlatformResponseCode.UnknownError;
        }

        public override string ToString()
        {
            return JsonUtil.ToJson(this);
        }
    }

    public enum PlatformResponseCode
    {
        [Description("成功")]
        RequestSuccess = 0,

        [Description("服务器异常,未知错误")]
        RequestError = 1,

        [Description("参数异常,请检查请求中是否缺少必传参数")]
        ParamError = 2,

        [Description("签名验证失败")]
        SignatureError = 3,

        [Description("权限验证失败，请检查外卖或者团购门店是否绑定")]
        AuthorityError = 4,

        [Description("令牌错误")]
        AppAuthTokenError = 5,

        [Description("ip不在白名单中")]
        IpError = 6,

        [Description("http请求方式错误")]
        RequestMethodError = 7,

        [Description("sql语句执行异常")]
        MysqlSyntaxError = 8,

        [Description("未知错误")]
        UnknownError = 9,
    }
}
